package top.zhimingw.service.impl;

import org.springframework.stereotype.Service;
import top.zhimingw.pojo.Menu;
import top.zhimingw.redis.MenuKey;
import top.zhimingw.service.BaseService;
import top.zhimingw.service.MenuService;

import java.util.List;

/**
 * @Author:zhimingw
 * @Version 1.0
 * @since 2021/6/1 16:40
 */
@Service("menuService")
public class MenuServiceImpl extends BaseService implements MenuService {
    @Override
    public boolean insert(Menu menu) {
        if(menuMapper.insert(menu)==1){
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteById(Integer id) {
        if(menuMapper.deleteById(id)==1){
            return true;
        }
        return false;
    }

    @Override
    public Menu queryById(Integer id) {
        return menuMapper.queryById(id);
    }

    @Override
    public List<Menu> queryAll() {
        return menuMapper.queryAll();
    }

    @Override
    public List<Menu> queryAll(Menu menu) {
        return menuMapper.queryAll(menu);
    }

    /**
    * @Description: 获取左侧菜单
    * @Param: []
    * @return: java.util.List<top.zhimingw.pojo.Menu>
    * @Author: zhimingw
    * @Date: 2021/6/1
    */
    @Override
    public List<Menu> getLeftMenus() {
        // 获取缓存中左侧菜单
        List<Menu> leftMenus = null;
        if (redisService.exists(MenuKey.getLeftMenu,"")) {
            leftMenus = redisService.getList(MenuKey.getLeftMenu, "", Menu.class);
        }else {
            leftMenus = menuMapper.queryAll(new Menu(0));
            // 获取并存入缓存
            redisService.setList(MenuKey.getLeftMenu,"",leftMenus);
        }
        return leftMenus;
    }

    /**
    * @Description: 获取右侧菜单
    * @Param: []
    * @return: java.util.List<top.zhimingw.pojo.Menu>
    * @Author: zhimingw
    * @Date: 2021/6/1
    */
    @Override
    public List<Menu> getRightMenus() {
        // 获取缓存中右侧菜单
        List<Menu> rightMenus = null;
        if (redisService.exists(MenuKey.getRightMenu,"")) {
            rightMenus = redisService.getList(MenuKey.getRightMenu, "", Menu.class);
        }else {
            rightMenus = menuMapper.queryAll(new Menu(1));
            // 获取并存入缓存
            redisService.setList(MenuKey.getRightMenu,"",rightMenus);
        }
        return rightMenus;
    }

    @Override
    public boolean update(Menu menu) {
        return false;
    }
}
